import smtplib
from email.mime.text import MIMEText
import configparser
import os

#读取配置文件
cp = configparser.ConfigParser()
cp.read("config.conf",encoding="utf-8")
cp_msg_from=cp.get('mail', 'msg_from')
cp_msg_password=cp.get('mail', 'password')
cp_msg_to=cp.get('mail', 'msg_to')


#发送邮件
def  send_mail(trade_msg):
    msg_from=cp_msg_from
    passwd=cp_msg_password
    msg_to=cp_msg_to
    subject="策略运行状态监测"
    content=trade_msg

    msg = MIMEText(content)
    msg["Subject"] = subject
    msg["From"] = msg_from
    msg["To"] = msg_to
    try:
        s = smtplib.SMTP_SSL("smtp.qq.com",465) #邮件服务器及端口号
        s.login(msg_from, passwd)
        s.sendmail(msg_from, msg_to, msg.as_string())
        print("发送成功")
    except s.SMTPException as e:
        print("发送失败")
        print(e)
    finally:
        s.quit()



